FROM resin/rpi-raspbian:buster
MAINTAINER Leonardo Loures <luvres@hotmail.com>

ENV NINJA_PATH=/usr/local/ninja \
	NNPACK_PATH=/usr/local/NNPACK

RUN \
	echo "alias ls='ls --color'" >>~/.bashrc \
	&& apt-get update \
	&& apt-get install -y \
		build-essential cmake pkg-config clang \
		git nano \
		python3-dev \
	  \
		libgflags-dev \
		libeigen3-dev \
		libavresample-dev \
		libgstreamer-plugins-base1.0-dev \
		gstreamer1.0-plugins-base-apps \
		libdc1394-22-dev \
		libgtk2.0-dev \
		libgtk-3-dev \
		libtesseract-dev \
		libavcodec-dev \
		libavformat-dev \
		libswscale-dev \
		libhdf5-dev \
		libgoogle-glog-dev \
	  \
		libjpeg-dev \
		libpng-dev \
		libtiff-dev \
		libv4l-dev \
		libxvidcore-dev \
		libx264-dev \
		libcanberra-gtk3-dev \
		libatlas-base-dev \
		gfortran \
	  \
		libopencv-dev \
  \
  	&& ln -s /usr/bin/python3 /usr/bin/python \
  \
  # Pip
  	&& curl https://bootstrap.pypa.io/get-pip.py | python \
  	&& rm ~/.cache/pip -fR \
  # Numpy
  	&& pip install numpy \
  # Install PeachPy and confu
  	&& pip install --upgrade git+https://github.com/Maratyszcza/PeachPy \
  	&& pip install --upgrade git+https://github.com/Maratyszcza/confu \
  \
  # Ninja-build
  	&& git clone https://github.com/ninja-build/ninja.git $NINJA_PATH \
	&& cd $NINJA_PATH \
	&& git checkout release \
	&& ./configure.py --bootstrap \
  \
  # NNPACK-darknet
  	&& git clone https://github.com/digitalbrain79/NNPACK-darknet.git $NNPACK_PATH \
  	&& cd $NNPACK_PATH && confu setup \
  	&& python ./configure.py --backend auto \
  	&& $NINJA_PATH/ninja \
  	&& cp -a lib/* /usr/lib/ \
  	&& cp include/nnpack.h /usr/include/ \
  	&& cp deps/pthreadpool/include/pthreadpool.h /usr/include/
